﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" type="text/css" href="../lib/layui/css/layui.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class=" layui-fluid">
<form id="myadd" class="layui-form layui-form-pane" lay-submit
      lay-filter="userForm" enctype="multipart/form-data">
    <div class="layui-collapse" lay-accordion="">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">主观题</h2>
            <div class="layui-colla-content" id="subjective">
<!--               3-->
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">分数</label>
        <div class="layui-input-block">
            <input type="text" name="subScore"  placeholder="请输入主观题总分数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="save" type="button" class="layui-btn" lay-submit lay-filter="formUser">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

    </div>

</form>
<script src="../lib/layui/layui.js"></script>
<script src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/xadmin.js"></script>
<script>
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return 1;
    }

    var eid = getUrlParam("eid")
    var sid = getUrlParam("sid")
    console.log(eid+"---")
    console.log(sid+"sid")
    $.ajax({
        type: "post",
        url: "/exam1/querySubjective",
        data: {"eid": eid,"sid":sid},
        success: function (res) {

            var content = "";
            for (var i = 0; i < res.data.length; i++) {
                content += "  <div class=\"layui-collapse\" lay-accordion=\"\" >" +
                    " <div class=\"layui-colla-item\" >\n" +
                    "                        <h2 class=\"layui-colla-title\">第" + (i + 1) + "题</h2>\n" +
                    "                        <div class=\"layui-colla-content layui-show\">\n" +
                    "                            <div>"+res.data[i].title+"</div>\n" +
                    "                            <div class=\"layui-form-item\">\n" +
                    "                                  <label name=\"sub" + res.data[i].id + "\" style='width: 100%;height: 200px' class=\"layui-form-label\" readonly=\"readonly\">"+res.data[i].answer.answer+"</label>"+
                    // "                                <!--                            <div class=\"layui-input-block\">-->\n" +
                    // "                                <input type=\"radio\" name=\"ch" + i + "\" value=\"1\" lay-skin=\"primary\" title=\"对\">\n" +
                    // "                                <input type=\"radio\" name=\"ch" + i + "\" value=\"2\" lay-skin=\"primary\" title=\"错\">\n" +
                    // "                                <!--                            </div>-->\n" +
                    "                            </div>\n" +
                    "                        </div>\n" +
                    "                    </div>"+
                    "                    </div>";
            }
            $("#subjective").html(content);
        }
    })

    layui.use(['element', 'layer','form'], function () {
        var element = layui.element;
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听折叠
        element.on('collapse(test)', function (data) {
            layer.msg('展开状态：' + data.show);
        });



        //监听提交
        form.on('submit(formUser)', function (data) {
            console.log(data.field)
            var subScore=data.field.subScore;
            var eid = getUrlParam("eid");
            var sid = getUrlParam("sid");
            console.log(subScore)
            console.log(eid)
            console.log(sid)
            $.ajax({
                url: '/exam1/submitSubScore',
                data:  {"eid": eid,"sid":sid,"subScore":subScore},
                method: "post",
                success: function (res) {
                    if (res.status==0){
                        alert("提交分数成功")
                        //重新加载父页面
                        parent.location.reload();

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }else if (res.status == 1) {
                        alert("添加失败（请检查分值或题目数）");
                    }
                },
                errors:function (res){
                    if (res.status == 1) {
                        alert("添加失败（请检查分值或题目数）");
                    }
                }
            })
            return false;
        });
    });
</script>

</body>


</html>